import { useEffect,useState } from "react";

function App() {
  const [count,setCount]=useState(0)
  const [obj,setObj]=useState({age:12})

  useEffect(()=>{
    console.log('处理副作用');
    document.title=`修改标题的次数：${count}`
  },[count])

  useEffect(()=>{
    console.log('相当于componentDidMount,只执行一次');
  },[])
  const add=()=>{
    setCount(count+1)
    
  }
  const changeObj=()=>{
    setObj({
      ...obj,
      age:Math.floor(Math.random()*10)
    })
  }
  return(
    <div>
      <h1>useEffect</h1>
      <p>{count}</p>
      <p>{obj.age}</p>
      <p><button onClick={add}>btn</button></p>
      <p><button onClick={changeObj}>changeObj</button></p>
    </div>
  )
}

export default App


